const { Schema, model } = require('mongoose')

const registrationSchema = new Schema({
  submitter: {
    type: Schema.ObjectId,
    ref: 'User',
    required: true
  },
  auditor: {
    type: Schema.ObjectId,
    ref: 'User',
    required: false
  },
  place: {
    type: Schema.ObjectId,
    ref: 'Place',
    required: true
  },
  auditDate: {
    type: Date,
    index: true,
    required: false
  },
  submitDate: {
    type: Date,
    required: true,
    index: true,
    default: () => Date.now()
  },
  reg_dwmc: {
    type: String,
    required: true
  },
  reg_dwbh: {
    type: String, // code + 许可证编号｜日期 + 序号
    required: true
  },
  reg_dwlb: {
    type: String, // type表中的code
    required: true
  },
  reg_xfxkzbh: {
    type: String,
    required: false
  },
  reg_fr: {
    type: String
  },
  reg_frdh: {
    type: String
  },
  reg_xffzr: {
    type: String,
    required: true
  },
  reg_xffzrdh: {
    type: String,
    required: true
  },
  reg_dwwxdj: {
    type: String
  },
  reg_wbdw: {
    type: String
  },
  reg_dwdz: {
    type: String
  },
  reg_dwxfjsjbqk: {
    type: String
  },
  reg_xzxq: {
    type: String
  },
  reg_syt: {
    type: [Schema.ObjectId],
    ref: 'File', // 示意图，图片地址
  },
  reg_status: {
    type: String,
    required: true,
    default: () => 'pending'
  },
  deleted: {
    type: Boolean,
    required: true,
    default: () => false
  },
  audit_suggestion: {
    type: String
  },
  note: {
    type: String
  }
})

const registrationModel = model('Registration', registrationSchema, 'Registration')

module.exports = registrationModel